/*
 * Copyright 2010 Christoph Widulle (christoph.widulle@googlemail.com)
 *
 * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the
 * License. You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS"
 * BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language
 * governing permissions and limitations under the License.
 */



package org.amarena2d.examples.scenes.invader;

import com.android1.amarena2d.actions.base.Action;
import com.android1.amarena2d.actions.base.FunctionAction;
import com.android1.amarena2d.actions.base.Sequence;
import com.android1.amarena2d.actions.ease.EaseBackIn;
import com.android1.amarena2d.actions.ease.EaseBackOut;
import com.android1.amarena2d.actions.instant.Visible;
import com.android1.amarena2d.actions.interval.DelayTime;
import com.android1.amarena2d.actions.movement.MoveIn;
import com.android1.amarena2d.actions.movement.MoveOut;
import com.android1.amarena2d.commons.VoidFunction;
import com.android1.amarena2d.engine.AmarenaEngine;
import com.android1.amarena2d.nodes.EntityGroup;
import com.android1.amarena2d.nodes.Scene;
import com.android1.amarena2d.nodes.SimpleLabel;
import com.android1.amarena2d.nodes.sprites.SharedSprite;
import com.android1.amarena2d.texture.BitmapFont;
import com.badlogic.gdx.graphics.Color;
import org.amarena2d.examples.Example;
//import com.badlogic.gdx.graphics.Font;

@Example(name = "Invader", category = "Demo Game")
public class InvaderLoadingScene extends Scene {

    final EntityGroup info;
    final Scene nextScene;

    private final VoidFunction nextSceneCall = new VoidFunction() {
        @Override
        public void exec() {
            engine.getDirector().runScene(nextScene);
        }
    };

    private final VoidFunction loadNextSceneCall = new VoidFunction() {
        @Override
        public void exec() {
            AmarenaEngine e = engine;
            nextScene.init();
            info.action().run(boxActionOut);
        }
    };

    final Action boxActionIn = Sequence.$(DelayTime.$(1F), Visible.$(true), EaseBackOut.$(MoveIn.$fromLeft(1)), FunctionAction.$(loadNextSceneCall));
    final Action boxActionOut = Sequence.$(EaseBackIn.$(MoveOut.$toRight(1)), FunctionAction.$(nextSceneCall));

    public InvaderLoadingScene() {

        this.info = new EntityGroup(112, 100);
        this.info.setVisible(false);
        add(info);

        this.nextScene = new InvaderExampleScene();

        final SharedSprite box = new SharedSprite("invader/box2.png");
        info.add(box);

        final SimpleLabel label = new SimpleLabel(engine.getFontManager().getFont("impact.fnt", "impact.png"), 112 / 2, 50, Color.WHITE).setAlign(BitmapFont.HAlignment.CENTER);
        label.setText("Loading...");
        info.add(label);




    }





    @Override
    protected void onEnterFinished() {
        info.action().run(boxActionIn);

    }


}